package com.zzdx.deployment.web.controller.apply;

import com.zzdx.deployment.common.annotation.Log;
import com.zzdx.deployment.common.base.AjaxResult;
import com.zzdx.deployment.common.enums.BusinessType;
import com.zzdx.deployment.common.page.TableDataInfo;
import com.zzdx.deployment.framework.web.base.BaseController;
import com.zzdx.deployment.system.domain.CompanyAndPc;
import com.zzdx.deployment.system.service.ICompanyService;
import com.zzdx.deployment.system.service.IPcService;
import com.zzdx.deployment.web.controller.msg.MSGUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业信息及批次信息
 * 
 * @author
 */
@Controller
@RequestMapping("/system/companyandpc")
public class ApplyController extends BaseController
{
    private String prefix = "system/companyandpc";

    @Autowired
    private ICompanyService companyService;
    @Autowired
    private IPcService pcService;

    @RequiresPermissions("system:companyandpc:view")
    @GetMapping()
    public String company()
    {
        return prefix + "/companyandpc";
    }
    /**
     * 查询企业列表
     */
    @RequiresPermissions("system:companyandpc:companyAndPcList")
    @PostMapping("/companyAndPcList")
    @ResponseBody
    public TableDataInfo getCompanyAndPclist(CompanyAndPc companyAndPc)
    {
        startPage();
        List<CompanyAndPc> list = companyService.selectCompanyAndPcList(companyAndPc);
        return getDataTable(list);
    }

    /**
     * 通过一级审核
     */
    @RequiresPermissions("system:companyandpc:apply")
    @Log(title = "通过审核", businessType = BusinessType.DELETE)
    @PostMapping( "/apply")
    @ResponseBody
    public AjaxResult apply(@RequestParam(name = "pcId") Integer pcId,
                            @RequestParam(name = "phone") String phone,
                            @RequestParam(name = "applyMsg") String applyMsg)
    {
        String msgIng = "申请信息已提交";
        String msgApply = "批次号 "+pcId.toString()+" 申请信息审核通过";
        String msgUnApply = "批次号 "+pcId.toString()+" 审核不通过";
        int resault = pcService.applyFirst(pcId,applyMsg);
        try {
            if (resault>0){
                if (applyMsg.equals("审核通过")){
//                    Boolean flag = MSGUtil.SendMsG(phone,msgApply);
                }
                if (applyMsg.equals("审核不通过")){
//                    Boolean flag = MSGUtil.SendMsG(phone,msgApply);
                }
            }
            return toAjax(resault);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toAjax(resault);
    }
}
